package com.ruoyi.wechat.service.impl;

import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.mapper.OrderDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.OrderMapper;
import com.ruoyi.wechat.domain.Order;
import com.ruoyi.wechat.service.IOrderService;

/**
 * 租赁Service业务层处理
 * 
 * @author 李硕
 * @date 2024-12-29
 */
@Service
public class OrderServiceImpl implements IOrderService 
{
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private OrderDetailServiceImpl orderDetailService;

    /**
     * 查询租赁
     * 
     * @param orderId 租赁主键
     * @return 租赁
     */
    @Override
    public Order selectOrderByOrderId(String orderId)
    {
        return orderMapper.selectOrderByOrderId(orderId);
    }

    /**
     * 查询租赁列表
     * 
     * @param order 租赁
     * @return 租赁
     */
    @Override
    public List<Order> selectOrderList(Order order)
    {
        return orderMapper.selectOrderList(order);
    }

    /**
     * 新增租赁
     * 
     * @param order 租赁
     * @return 结果
     */
    @Override
    public int insertOrder(Order order)
    {
        String uuid = IdUtils.randomUUID();
        order.setOrderId(uuid);
        for (int i = 0; i < order.getOrderDetails().size(); i++) {
            order.getOrderDetails().get(i).setOrderId(order.getOrderId());
            order.getOrderDetails().get(i).setOrderDetailId(IdUtils.randomUUID());
            orderDetailService.insertOrderDetail(order.getOrderDetails().get(i));
        }
        int i = orderMapper.insertOrder(order);

        return i;
    }


    @Override
    public String WxInsertOrder(Order order)
    {
        String uuid = IdUtils.randomUUID();
        order.setOrderId(uuid);
        for (int i = 0; i < order.getOrderDetails().size(); i++) {
            order.getOrderDetails().get(i).setOrderId(order.getOrderId());
            order.getOrderDetails().get(i).setOrderDetailId(IdUtils.randomUUID());
            orderDetailService.insertOrderDetail(order.getOrderDetails().get(i));
        }
        int i = orderMapper.insertOrder(order);
        if (i >0) {
            return uuid;
        }
        return i+"";
    }

    /**
     * 修改租赁
     * 
     * @param order 租赁
     * @return 结果
     */
    @Override
    public int updateOrder(Order order)
    {
        return orderMapper.updateOrder(order);
    }

    /**
     * 批量删除租赁
     * 
     * @param orderIds 需要删除的租赁主键
     * @return 结果
     */
    @Override
    public int deleteOrderByOrderIds(String[] orderIds)
    {
        return orderMapper.deleteOrderByOrderIds(orderIds);
    }

    /**
     * 删除租赁信息
     * 
     * @param orderId 租赁主键
     * @return 结果
     */
    @Override
    public int deleteOrderByOrderId(String orderId)
    {
        return orderMapper.deleteOrderByOrderId(orderId);
    }
}
